package top.zsyle.basic.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.zsyle.basic.dto.*;
import top.zsyle.basic.service.LoginService;
import top.zsyle.basic.util.AjaxResult;
import top.zsyle.basic.vo.LoginVo;

import javax.validation.Valid;

@RestController
@RequestMapping("/login")
public class LoginController {

    @Autowired
    private LoginService loginService;


    @PostMapping("/account")
    public AjaxResult login(@RequestBody @Valid LoginDto dto) {
        return AjaxResult.me().success(loginService.account(dto));
    }

    @PostMapping("/code")
    public AjaxResult smscodeLogin(@RequestBody @Valid LoginCodeDto dto) {
        return AjaxResult.me().success(loginService.smscodeLogin(dto));
    }

    /**
     * 微信扫码登录
     *
     * @param dto
     * @return
     */
    @PostMapping("/wechat")
    public AjaxResult wechat(@RequestBody @Valid WeChatDto dto) {
        return loginService.wechat(dto);
    }

    /**
     * 微信扫码绑定手机
     *
     * @param dto
     * @return
     */
    @PostMapping("/wechat/binder")
    public AjaxResult phoneBinder(@RequestBody @Valid BinderDto dto) {
        return AjaxResult.me().success(loginService.phoneBinder(dto));
    }
}
